package lumis.portal.fileparser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import lumis.portal.PortalException;

/**
 * Manages the parsing of files.
 * 
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class FileParserManager implements IFileParserManager
{
	/**
	 * Chain of parsers to be applied on a file.
	 * @since 6.0.0
	 */
	private List<IFileParser> parserChain;

	/**
	 * Constructor.
	 * 
	 * @since 6.0.0
	 */
	public FileParserManager()
	{
		parserChain = new ArrayList<IFileParser>();

		// adds the parser to the chain
		parserChain.add(new FFMPEGFileParser());
		parserChain.add(new ImageFileParser());
	}

	public IFileMetadata extractMetadata(File file, String contentType) throws PortalException
	{
		FileMetadata metadata = new FileMetadata();

		for (IFileParser parser : parserChain)
		{
			parser.extractMetadata(file, contentType, metadata);
		}

		return metadata;
	}

}
